package com.qms.tubu.decoration;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by Mad on 2015/7/17.
 */
public class GridItemDecoration extends RecyclerView.ItemDecoration{
    private int space;
    private int margin;
    public GridItemDecoration() {
        space=0;
        margin=0;
    }
    public GridItemDecoration(int space,int margin)
    {
        this.space=space;
        this.margin=margin;
    }
    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        int position=parent.getChildAdapterPosition(view);
        if(position==0 ||position==parent.getAdapter().getItemCount()-1)
        {
            outRect.left=0;
            outRect.top=0;
            outRect.right=0;
            outRect.bottom=0;
            return;
        }
        position=position-1;
        if(position%2==0)
        {
            outRect.left=space+margin;
            outRect.right=space;
            outRect.bottom=space;
            outRect.top=space;
        }
        else
        {
            outRect.left=space;
            outRect.right=space+margin;
            outRect.bottom=space;
            outRect.top=space;
        }
    }
}
